<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<title>时钟</title>
		<style>
			div{
				font-size: 30px;
				margin-top:300px;
				margin-left: 500px;
				color: red;
				
			}
		</style>
		
	</head>
	<body onload="time() ">

			<div id="myclock">
				
			<div/>
	</body>
	
	<script>
		//为什么script要放后面
				function time(){
					var today = new Date();
					var nian = today.getFullYear();
					var yue = today.getMonth();
					var ri = today.getDate();
					var xq = today.getDay();
					var hh = today.getHours();
					var ff = today.getMinutes();
					var mm = today.getSeconds();
					var str ="";													
					if(parseInt(ri) > 12) {
						str += "现在是："+nian+"年"+(yue+1)+ "月"+ri+"日&nbsp;" + hh + ":" + ff + ":" + mm + "&nbsp;pm" + "&nbsp;星期"+xq+"<br/>";
					} else {
						str += "现在是："+nian+"年"+yue+ "月"+ri+"日&nbsp;" + hh + ":" + ff + ":" + mm + "&nbsp;am" +"&nbsp;星期"+xq+"<br/>";
					}
					//document.write(str);
					
					document.getElementById("myclock").innerHTML =  str;
				}
				var mytime = setInterval("time()",1000);
			</script>
</html>
